using System;
using Jinjia.Core.ScheduleProvider.Attribute;
using Jinjia.Approve.ScheduleJobAPI.Controllers.Base;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace Jinjia.Approve.ScheduleJobAPI.Controllers
{
    public class SayHelloJobController : BaseJobController
    {
        private readonly ILogger<SayHelloJobController> _logger;

        public SayHelloJobController(ILogger<SayHelloJobController> logger) : base(logger)
        {
            _logger = logger;
        }

        [HttpGet]
        [Route("SayHello")]
        [ScheduleJob("SayHello", "SayHello", "0 0/10 * * * ?", "计划任务示例")]
        public IActionResult SayHello()
        {
            RunScheduleJob(
                () => { Console.WriteLine("Hello!"); },
                e => { _logger.LogError("捕获异常{E}", e.Message); }
            );
            return Success();
        }
    }
}